function maxSubArray(nums: number[]): number {
    let pre = 0;
    let max = nums[0];

    nums.forEach((r: number) => {
        pre = Math.max(pre + r, r);
        max = Math.max(max, pre)
    })
    return max;
};